// 电脑随机生成2个整数，作为电脑下棋的座标，赋给board数组。 
// 还涉及 
//                    1.座标的有效性，只能是数字，不能超出棋盘范围 
//                    2.如果下的棋的点，不能重复下棋。 
//                    3.每次下棋后，需要扫描谁赢了
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.*;
public   class  Number6 { 
	//定义一个二维数组来充当棋盘      
 	private  String[][] board;      
	//定义棋盘的大小      
	private   static   int  BOARD_SIZE =  15 ;      
	public   void  initBoard() {          
       	//初始化棋盘数组         
   		board =  new  String[BOARD_SIZE][BOARD_SIZE];          
   		//把每个元素赋为"╋"，用于在控制台画出棋盘          
       	for  ( int  i =  0 ; i < BOARD_SIZE; i++) {              
       		for  ( int  j =  0 ; j < BOARD_SIZE; j++) {                 
       			board[i][j] =  "╋" ;             
       		}         
       	}     
   	}      
   	//在控制台输出棋盘的方法
   	public   void  printBoard() { 
   		//打印每个数组元素          
       	for  ( int  i =  0 ; i < BOARD_SIZE; i++) { 
       		for  ( int  j =  0 ; j < BOARD_SIZE; j++) { 
       		//打印数组元素后不换行                 
       			System.out.print(board[j][i]);             
       		}              
       		//每打印完一行数组元素后输出一个换行符             
       		System.out.print( "/n" );         
       	}     
   	}      
   	public  String checkWin( int  x,  int  y, String color) {
   		int  x1;          
	   	int  x2;          
	   	int  y1;          
	   	int  y2;
	   	//横          
	   	          
       	if  (x -  4  >  0 ) {             
       		x1 = x -  4 ;         
   		}  else  {             
       		x1 =  0 ;         
   		}          
   		if  (x +  4  <  15 ) {             
       		x2 = x +  4 ;         
   		}  else  {             
       		x2 =  14 ;         
   		}          
   		if  (y -  4  >  0 ) {             
       		y1 = y -  4 ;         
   		}  else  {             
       		y1 =  0 ;         
   		}          
   		if  (y +  4  <  15 ) {             
       		y2 = y +  4 ;         
   		}  else  {             
       		y2 =  14 ;         
   		}
   		//横          
   		int  result =  0 ;          
   		for  ( int  i = x1; i <= x2; i++) {              
       		if  (result !=  5 ) {                  
           		if  (i <  0  || i >  15  || y <  0  || y >  15 ) {                     
               		System.out.println( "error" );                 
           		}                  
           		if  (board[i][y] == color) {                     
               		result++;                 
           		}  else  {                     
           			result =  0 ;                 
           		}             
       		}  else  {                  
           		return  color +  " Win!!" ;             
       		}         
   		}            
   		if  (result ==  5 ) {                
       		return  color +  " Win!!" ;          
   		}
   		//竖         
   		result =  0 ;          
   		for  ( int  i = y1; i <= y2; i++) {              
       		if  (result !=  5 ) {                  
           		if  (x <  0  || x >  15  || i <  0  || i >  15 ) {                     
               		System.out.println( "error" );                 
           		}                  
           		if  (board[x][i] == color) {                     
               		result++;                 
           		}  else  {                     
               		result =  0 ;                 
           		}             
       		}  else  {                  
           		return  color +  " Win!!" ;             
       		}         
   		}            
   		if  (result ==  5 ) {                
       		return  color +  " Win!!" ;          
   		}
   		//向左斜         
   		result =  0 ;          
   		int  moveX =  0 ;          
   		int  moveY =  0 ;
   		if  (x - x1 >= y - y1) {             
       		moveX = y - y1;         
   		}  else  {             
       		moveX = x - x1;         
   		}

   		if  (x2 - x >= y2 - y) {             
       		moveY = y2 - y;         
   		}  else  {             
       		moveY = x2 - x;         
   		}          
   		for  ( int  i = -moveX; i <= moveY; i++) {              
       		if  (result !=  5 ) {                  
           		if  (x + i <  0  || x + i >  15  || y + i <  0  || y + i >  15 ) {                     
           			System.out.println( "error" );                 
           		}                  
           		if  (board[x + i][y + i] == color) {                     
               		result++;                 
           		}  else  {                     
               		result =  0 ;                 
       			}             
       		}  else  {                  
           		return  color +  " Win!!" ;             
       		}         
   		}           
   		if  (result ==  5 ) {                
       		return  color +  " Win!!";          
   		}           	   	         
       		//向右斜         
   		result =  0 ;          
   		int  moveX2 =  0 ;          
   		int  moveY2 =  0 ;          
   		if  (x - x1 >= y2 - y) {             
       		moveX2 = y2 - y;         
   		}  else  {             
       		moveX2 = x - x1;         
   		}          
   		if  (x2 - x >= y - y1) {             
       		moveY2 = y - y1;         
   		}  else  {          
       		moveY2 = x2 - x;         
   		}         
   		for  ( int  i = -moveX2; i <= moveY2; i++) {              
       		if  (result !=  5 ) {                  
           		if  (x + i <  0  || x + i >  15  || y - i <  0  || y - i >  15 ) {                     
               		System.out.println( "error" );                 
           		}                  
           		if  (board[x + i][y - i] == color) {                     
           			result++;                 
           		}  else  {                     
               		result =  0 ;                 
           		}             
       		}  else  {                  
           		return  color +  " Win!!" ;             
       		}         
   		}           
   		if  (result ==  5 ) {                
       		return  color +  " Win!!" ;          
   		}          
   		return   null ;     
    }
    public   static   void  main(String[] args)  throws  Exception {         
   		Number6 gb =  new  Number6();         
   		gb.initBoard();         
   		gb.printBoard();         
   		System.out.println( "请输入您下棋的座标，应以x,y的格式：" );          
   		//这是用于获取键盘输入的方法         
   		BufferedReader br =  new  BufferedReader( new  InputStreamReader(System.in));         
   		String inputStr =  null ;          
   		br.readLine();
   		//每当在键盘上输入一行内容按回车，刚输入的内容将被br读取到。          
       		while  ((inputStr = br.readLine()) !=  null ) {              
	       		//将用户输入的字符串以逗号（,）作为分隔符，分隔成2个字符串             
	       		String[] posStrArr = inputStr.split( "," );              
	       		//将2个字符串转换成用户下棋的座标              
	       		int  xPos = Integer.parseInt(posStrArr[ 0 ]);              
	       		int  yPos = Integer.parseInt(posStrArr[ 1 ]);              
	       		//把对应的数组元素赋为"●"。             
	       		gb.board[xPos -  1 ][yPos -  1 ] =  "●" ;             
	       		String win = gb.checkWin(xPos -  1 , yPos -  1 ,  "●" ); 
	       		//每次下棋后，需要扫描谁赢了              
	       		if  (win !=  null ) {                 
		       		gb.printBoard();                 
		       		System.out.println(win);                 
		       		System.exit( 0 );             
	       		}              
	       		int  aiX;              
	       		int  aiY;              
	       		while  ( true ) {                 
		       		Random r1 =  new  Random();                 
		       		aiX = r1.nextInt(BOARD_SIZE -  1 ); 
		       		//座标的有效性，只能是数字，不能超出棋盘范围                 
		       		Random r2 =  new  Random();                 
		       		aiY = r2.nextInt(BOARD_SIZE -  1 );                  
		       		if  (gb.board[aiX][aiY] ==  "╋" ) {  
		       		//如果下的棋的点，不能重复下棋。                     
		       		gb.board[aiX][aiY] =  "○" ;                      
		       		break ;                 
	       			}             
	       		}             
	       		win = gb.checkWin(aiX, aiY,  "○" );  
	       		//每次下棋后，需要扫描谁赢了              
	       		if  (win !=  null ) {                 
	       			gb.printBoard();                 
	       			System.out.println(win);                 
	       			System.exit( 0 );             
	       		}             
	       		gb.printBoard();             
	       		System.out.println( "请输入您下棋的座标，应以x,y的格式：" );         
       	}     
   }
}
     